<!--# layout("/templates/layout/layout_main.html",{"title":"角色管理","nameSpace":"role_admin","breadcrumbs":[{"name":"角色管理"}]}){ #-->
	<table id="listTable" class="table  table-hover general-table table-striped table-bordered no-margin-bottom " >
		<thead>
			<thead>
			<tr>
				<th colspan="4">
					<div class="row">
						<div class="col-md-3 ">
							<form action="${base}/role/list" method="post" class="search-form">
								<div class="input-group">
									<span class="input-group-addon">关键字</span> <input type="text" class="form-control" placeholder="请输入关键词进行检索..." style="font-weight: 500" name="key"
										value="" data-default="Search..." data-error="请输入搜索关键词" >
									<span class="input-group-addon search-btn" style="cursor: pointer;"><i class="fa fa-search"></i> GO</span>
								</div>
							</form>
						</div>
						<div class="col-md-2 col-md-offset-7">
							<a href="javascript:toEdit();"  class="btn btn-info btn-sm"><i class="fa fa-plus-circle"></i> 新增角色</a>
						</div>
					</div>
				</th>
			</tr>
			<tr>
				<th class="center">序号</th>
				<th class="center">角色KEY</th>
				<th class="center">角色名称</th>
				<th class="center">操作</th>
			</tr>
		</thead>
		<tbody>
			<!--# if(obj.data.roles.~size > 0){ #-->
				<!--# for(role in obj.data.roles){ #-->
				<tr data-id="${role.id}">
					<td  class="center"> ${roleLP.index}</td>
					<td  class="">${role.name}</td>
					<td  class="" >${role.description}</td>
					<td class="center">
						<div class="hidden-sm hidden-xs btn-group">
							<a class="btn btn-xs btn-warning" title="编辑" href="javascript:toEdit(${role.id})">
								<i class="ace-icon fa fa-pencil-square-o bigger-120" title="编辑" ></i>
							</a>
							<a class="btn btn-xs btn-danger" title="删除" onclick="toDel('${role.id}');">
								<i class="ace-icon fa fa-trash-o bigger-120" title="删除"></i>
							</a>
						</div>
					</td>
				</tr>
				<!--# } #-->
			<!--#}else{ #-->
				<tr class="main_info">
					<td colspan="4" class="center">没有相关数据</td>
				</tr>
			<!--# } #-->
		</tbody>
	</table>
	<div class="" id="dialogs">
		<div id="editDialog" class="hidden">
			<div  class="hr-30"></div>
			<form id="edit-form" class="form-horizontal" role="form" method="post">
				<input type="hidden" id="form-field-id" name="id" value=""/>
				<div class="form-group" style="margin-left:5px;width:97%;">
					<label for="form-field-name" class="col-sm-3 control-label no-padding-right">角色KEY</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" id="form-field-name" name="name" data-type='required' data-error='请输入的角色KEY'  placeholder="请输入的角色KEY" value="" />
					</div>
				</div>
				
				<div class="form-group" style="margin-left:5px;width:97%;">
					<label for="form-field-desc" class="col-sm-3 control-label no-padding-right">角色名称</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" id="form-field-desc" name="description" data-type='required' data-error='请输入角色名称' placeholder="请输入角色名称" value="" />
					</div>
				</div>
				<div class="hr-30" ></div>
			</form>
		</div>
	</div>
	<script src="${base}/assets/biz-logic/js/ztree/jquery.ztree.all.min.js"></script>
	<script type="text/javascript">
	$(function($) {
		
	});
	
	function toEdit(id){
		layer.open({
			  type: 1,
			  title:id?'编辑角色':'添加角色',
			  skin: 'layui-layer-rim', //加上边框
			  area: ['320px', '250px'], //宽高
			  content: $('#editDialog'),
			  btn: ['保存','取消'], //按钮
			  yes:function(){
				  if ($('#edit-form').find('input,select').validation()) {//验证表单
						var myform = $('#edit-form') ;
						$.ajax({
							type:'post',
							url:$('#edit-form').attr("action"),
							data:$('#edit-form').serialize(),
							dataType:'json',
							success:function(result) {
							if (result.operationState == 'SUCCESS') {
								layer.closeAll();
								location.href = getRootPath() + "/role/list";
							} else {
								layer.msg(result.data.reason);
							}
						}});
					}
			  },
			  btn2:function(){
				  layer.closeAll();
			  }
			});
		$('#editDialog').removeClass("hidden");
		if(id){
			$('#edit-form input[name=id]').val(id);
			$('#edit-form input[name=name]').val($('#listTable tr[data-id='+ id +'] td:eq(1)').text());
			$('#edit-form input[name=description]').val($('#listTable tr[data-id='+ id +'] td:eq(2)').text());
			$('#edit-form').attr("action", getRootPath() + '/role/update');
		}else{
			$('#edit-form input[name=id]').val('');
			$('#edit-form input[name=name]').val('');
			$('#edit-form input[name=description]').val('');
			$('#edit-form').attr("action", getRootPath() + '/role/add');
		}
		
		
	}
	/**
	 移除用户
	*/
	function toDel(id){
		if(id == ''){
			return;
		}
		layer.confirm('确定要删除该角色？',function(){
			$.post(getRootPath() + '/role/batchDel', {ids:id}, function(r) {
				if (r.operationState == 'SUCCESS') {
					$('#listTable tr[data-id='+ id +']').remove();
					layer.closeAll();
				} else {
					layer.msg(r.data.reason);
				}
			}, 'json');
		});
	}
	
</script>
<!--# } #-->

 